package com.software.graduationproject.modules.user.web;

import com.baomidou.mybatisplus.core.metadata.Page;

import com.software.graduationproject.commons.select.Select;
import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.user.entity.UserAddress;
import com.software.graduationproject.modules.user.object.UserAddressVo;
import com.software.graduationproject.modules.user.service.UserAddressService;
import com.software.graduationproject.modules.user.object.UserAddressCreateQo;
import com.software.graduationproject.modules.user.object.UserAddressUpdateQo;

import com.v2coding.validate.CreateGroup;
import com.v2coding.validate.UpdateGroup;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * UserAddressController : 用户地址表
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/User/UserAddress")
@Api(value = "API - 用户地址表", tags = {"用户地址表接口"})
public class UserAddressController {

    @Autowired
    private UserAddressService userAddressService;

    @PostMapping("/create")
    @ApiOperation("新增用户地址表")
    public Result createQo(@RequestBody @Validated(CreateGroup.class) UserAddressCreateQo qo) {
        userAddressService.createQo(qo);
        return Results.success();
    }

    @PostMapping("/update")
    @ApiOperation("修改用户地址表")
    public Result updateQo(@RequestBody @Validated(UpdateGroup.class) UserAddressUpdateQo qo) {
        userAddressService.updateQo(qo);
        return Results.success();
    }

    @PostMapping("/delete")
    @ApiOperation("删除用户地址表")
    public Result delete(@RequestBody Long id) {
        userAddressService.delete(id);
        return Results.success();
    }
//
//    @PostMapping("/deleteList")
//    @ApiOperation("批量删除用户地址表")
//    public Result deleteList(@RequestBody Long []ids) {
//        userAddressService.deleteList(ids);
//        return Results.success();
//    }
//
//    @GetMapping("/select")
//    @ApiOperation("查询用户地址表详情")
//    public Result<UserAddressVo> selectVo(Long id) {
//        UserAddressVo userAddressVo = userAddressService.selectVo(id);
//        return Results.success(userAddressVo);
//    }

    @GetMapping("/selectList")
    @ApiOperation("查询用户地址表列表")
    @ApiImplicitParams({ //
            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
    })
    public Result<List<UserAddressVo>> selectListVo(@ApiIgnore Select select) {
        List<UserAddressVo> userAddressVoList = userAddressService.selectListVo(select);
        return Results.success(userAddressVoList);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询用户地址表分页")
    @ApiImplicitParams({ //
            @ApiImplicitParam(name = "select", value = "查询条件", required = false, dataTypeClass = String.class, paramType = "query"),//
    })
    public Result<Page<UserAddressVo>> selectPageVo(@ApiIgnore Select select) {
        Page<UserAddressVo> userAddressVoPage = userAddressService.selectPageVo(select);
        return Results.success(userAddressVoPage);
    }


}
